package com.huang.eduservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huang.eduservice.client.VodClient;
import com.huang.eduservice.entity.EduChapter;
import com.huang.eduservice.entity.EduVideo;
import com.huang.eduservice.entity.chapter.ChapterVo;
import com.huang.eduservice.service.EduChapterService;
import com.huang.eduservice.service.EduVideoService;
import com.hunag.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-03-21
 */
@RestController
@RequestMapping("/eduservice/edu-chapter")
public class EduChapterController {
    @Autowired
    private EduChapterService service;


    @GetMapping("getChapterVideo/{courseId}")
    public R getChapterVideo(@PathVariable String courseId) {
        List<ChapterVo> list = service.getChapterVideo(courseId);
        return R.ok().data("allChapterVo", list);
    }

    @PostMapping("addChapter")
    public R addChapter(@RequestBody EduChapter eduChapter) {
        service.addChapter(eduChapter);
        return R.ok();
    }

    @GetMapping("getChapterByid/{id}")
    public R getChapterByid(@PathVariable String id) {
        EduChapter eduChapter = service.getChapterByid(id);
        return R.ok().data("eduChapter", eduChapter);
    }

    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter chapter) {
        service.updateChapter(chapter);
        return R.ok();
    }

    @DeleteMapping("deleteChapter/{id}")
    public R deleteChapter(@PathVariable String id) {

        String msg = service.deleteChapter(id);
        return R.ok().data("msg", msg);
    }

}

